package a_airwar;

public class Hero extends FlyObj {
    private int doubleFire;
    private int index;
    private int score;
    int xStep = this.getWidth()/4;
    /* public Hero() {
         image = JFrameMain.hero;
         width = image.getWidth();
         height = image.getHeight();
         x = 240;
         y = 500;
         index = 0;
     }*/
    public Hero() {
        //使用private修饰之后 所有的成员变量都访问不到
        //只能使用super关键词调用 - 调用父类的构造方法
        super(200, 500, JFrameMain.hero0, 3);
        index = 0;

    }

    @Override
    public void move() {
        index++;
        if (index % 2 == 0) {
            this.setImage(JFrameMain.hero0);
        } else
            this.setImage(JFrameMain.hero1);
       /* index++;
        if (index > 1)
            index = 0;
        try {
            JFrameMain.hero = ImageIO.read(JFrameMain.class.getResourceAsStream("pic/hero" + index + ".png"));
        } catch (IOException e) {
            e.printStackTrace();
        }*/
    }

    //发射子弹
    //1颗或者2颗子弹
    private Bullet[] bullets;

    public Bullet[] shoot() {
        //Bullet[]->引用类型数组
        //1.给数组初始化——长度
        if (doubleFire == 0) {
            bullets = new Bullet[1];
            //2.给数组元素初始化
            bullets[0] = new Bullet(this.getX() + JFrameMain.hero0.getWidth() / 2, this.getY());
            return bullets;
        }
        else {
            doubleFire-=2;
            bullets=new Bullet[2];
            bullets[0]=new Bullet(this.getX()+3*xStep,this.getY());
            bullets[1] = new Bullet(this.getX() + 1*xStep,
                    this.getY());
            return bullets;
        }
    }

    public void doubleFire() {
        doubleFire += 20;
    }

    // 英雄机随着鼠标移动
    public void mouseMove(int mouse_x, int mouse_y) {
        this.setX(mouse_x - JFrameMain.hero0.getWidth() / 2); //使得英雄机中心对准在鼠标
        this.setY(mouse_y - JFrameMain.hero0.getHeight() / 2);
    }



    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public void addScore(int score) {
        this.setScore(this.getScore() + score);
    }

    // 加命
    public void addLife() {
        this.setLife(this.getLife() + 1);

    }
}